<%-- 
    Document   : raportTmpl
    Created on : Feb 13, 2014, 12:45:45 PM
    Author     : Marek
--%>
<%@page import="util.Info"%>
<%@page import="entities.users.AdminUser"%>
<%@page import="entities.tools.Form"%>
<%@page import="entities.tools.FilledForm"%>
<%@page import="entities.tools.Answer"%>
<%@page import="util.other.ENUMQuestionTypes"%>
<%@page import="entities.tools.Question"%>
<%@page import="java.util.ArrayList"%>
<%@page import="control.AbstractServlet1.FormGenerator"%>
<%@page import="control.AbstractServlet1.FormInfo"%>
<%@page import="control.AbstractServlet1.FormField"%>
<%@page import="control.AbstractServlet1.FormButton"%>
<%@page contentType="text/html;charset=UTF-8" language="java" %>
<%@page isELIgnored="false" %> 
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<div style="width:97%;height:100%;">
    <div><ul><li><a href="<c:url value="?action=newUser"/>">New Form Owner</a></li></ul></div>
    <div style="display:table;width:100%;">
        <div style="display:table-row;width:100%;">
            <div style="display:table-cell;width:80%;overflow:scroll;">
                    <form method="post" action="">
                    <table border="1" style="width:100%;font-size:10px;">
                        <tr>
                            <c:set var="formFields" value="${searchByAdminUser.formFields}"/>
                            <c:forEach items="${formFields}" var="field">
                                <c:set var="orderByStyle" value="" scope="request"/>                  
                                <c:choose>
                                    <c:when test="${orderByColumn eq field.name}">
                                        <c:set var="orderByStyle" value="background-color:green;border:1px solid black;color:yellow;font-weight:bold;" scope="request"/>                  
                                        <c:choose>
                                            <c:when test="${orderByDirection eq 'ASC'}">
                                                <c:set var="orderByDirectionArrow" value="&#8595;"/>                  
                                            </c:when>
                                            <c:when test="${orderByDirection eq 'DESC'}">
                                                <c:set var="orderByDirectionArrow" value="&#8593;"/>                  
                                            </c:when>
                                        </c:choose>
                                    </c:when>
                                    <c:otherwise>
                                        <c:set var="orderByDirectionArrow" value=""/>                  
                                    </c:otherwise>
                                </c:choose>
                                <th style="${orderByStyle}"><a style="${orderByStyle}" href="?action=orderBy&columnName=${field.name}">${field.description}${orderByDirectionArrow}</a></th>
                                </c:forEach>
                            <th>&nbsp;</th>
                            <th>&nbsp;</th>
                        </tr>
                        
                            <input type="hidden" name="formName" value="searchBy"/>
                            <tr>
                                <c:set var="formFields" value="${searchByAdminUser.formFields}"/>
                                <c:forEach items="${formFields}" var="field">
                                    <td><input type="text" value="${field.value}" name="${field.name}" style="width:100%;"/></td>
                                    </c:forEach>
                                <td><input type="submit" value="search" style="width:100%;"/></td>
                                <td>&nbsp;</td>
                            </tr>
                        
                        <c:forEach items="${entities}" var="entity">
                            <c:set var="selectedRowStyle" value=""/>
                            <c:choose>
                                <c:when test="${entity eq selectedEntity}">
                                    <c:set var="selectedRowStyle" value="background-color:#EEEEEE;border:1px solid black;"/>                  
                                </c:when>
                            </c:choose>

                            <tr style="${selectedRowStyle}">
                                <c:set var="formFields" value="${entity.formFields}"/>
                                <c:forEach items="${formFields}" var="field">
                                    <td>${field.value}</td>
                                </c:forEach>
                                <td><a href="<c:url value="?action=deleteUser&id=${entity.id}"/>">Delete</a></td>
                                <td><a href="<c:url value="?action=selectUser&id=${entity.id}"/>">Select</a></td>
                            </tr>
                        </c:forEach>
                    </table> 
                    </form>

            </div>
            <div style="display:table-cell;width:20%;">
                <c:choose>
                    <c:when test="${not empty selectedEntity}">
                        <form method="POST" action="">
                            <input type="hidden" name="formName" value="editUser"/>
                            <table>
                                <c:set var="formFields" value="${selectedEntity.formFields}"/>
                                <c:forEach items="${formFields}" var="field">
                                    <tr>
                                        <td>${field.description}</td><td><input type="text" name="${field.name}" value="${field.value}"/></td>
                                    </tr>
                                </c:forEach>
                                <td colspan="2">
                                    <a href="<c:url value="?action=closeUser"/>">Close</a>
                                    <input value="Save" type="submit"/><!-- use it as a image button same as at global form-->
                                </td>
                            </table>


                        </form>
                    </c:when>
                    <c:otherwise>

                    </c:otherwise>
                </c:choose>


            </div>
        </div>
    </div>

</div>

